package com.dissertation.model;

import com.dissertation.model.auth.Role;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.Collections;

// 分类的 树节点 unique_name就是名字
// 一级目录
@Document
public class CategoryTree extends MongodbBaseModel {

    private List<CategoryLeaf> categoryLeaves = Collections.emptyList();

    @NotNull
    private Set<Role> role = Collections.emptySet();

    public Set<Role> getRole() {
        return role;
    }

    public void setRole(Set<Role> role) {
        this.role = role;
    }

    public List< CategoryLeaf > getCategoryLeaves( ) {
        return categoryLeaves;
    }

    public void setCategoryLeaves( List< CategoryLeaf > categoryLeaves ) {
        this.categoryLeaves = categoryLeaves;
    }

    public void addRoles( Role... roles ) {
        role = Optional.ofNullable( role ).orElse( new HashSet<>() );
        role.addAll( Arrays.asList( roles ) );
    }
}
